package com.example.shortlink.dao.mapper;

import com.example.shortlink.dao.entity.LinkStatsToday;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * 短链接今日统计持久层
 */
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsToday> {
    @Insert("<script>" +
            "INSERT INTO " +
            "t_link_stats_today " +
            "(" +
            "full_short_url, " +
            "gid, " +
            "date,  " +
            "today_uv, " +
            "today_pv, " +
            "today_uip, " +
            "create_time, " +
            "update_time, " +
            "del_flag" +
            ") " +
            "VALUES" +
            "( " +
            "#{linkTodayStats.fullShortUrl}, " +
            "#{linkTodayStats.gid}, " +
            "#{linkTodayStats.date}, " +
            "#{linkTodayStats.todayUv}, " +
            "#{linkTodayStats.todayPv}, " +
            "#{linkTodayStats.todayUip}, " +
            "NOW(), " +
            "NOW(), " +
            "0" +
            ") " +
            "ON DUPLICATE KEY UPDATE today_uv = today_uv +  #{linkTodayStats.todayUv}, " +
            "today_pv = today_pv +  #{linkTodayStats.todayPv}, " +
            "today_uip = today_uip +  #{linkTodayStats.todayUip}" +
            "</script>")
    void shortLinkTodayState(@Param("linkTodayStats") LinkStatsToday linkStatsTodayDO);
}
